﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Accounting.Web.Models;

namespace Accounting.Views
{
    public partial class Warehouses : ChildWindow
    {
        public Warehouses()
        {
            InitializeComponent();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void warehouseDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Record will be deleted. Are you sure?", "Confirmation", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                warehouseDomainDataSource.DataView.Remove(warehouseDomainDataSource.DataView.CurrentItem);
                warehouseDomainDataSource.SubmitChanges();
            }
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Warehouse warehouse = new Warehouse();
            warehouse.Synced = false;
            warehouse.Name = txtWarehouse.Text;
            warehouseDomainDataSource.DataView.Add(warehouse);
            warehouseDomainDataSource.SubmitChanges();
        }
    }
}

